"""System tools"""

import os
import platform
import socket


def get_desktop_path():
    if "Darwin" in platform.system():  # 'Darwin' is the system name for macOS
        return os.path.join(os.path.expanduser("~"), "Desktop")
    else:
        raise EnvironmentError("This function is only for MacOS.")


def extract_ip():
    st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        st.connect(("10.255.255.255", 1))
        IP = st.getsockname()[0]
    except Exception:
        IP = "127.0.0.1"
    finally:
        st.close()
    return IP
